package com.xuln.mybatis.dao;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionFactioryUtil {
	private static String resource = "org/mybatis/example/Configuration.xml";
	private static SqlSessionFactory sessionFactory;

	public static SqlSessionFactory getSessionFactory() {
		Reader reader;
		try {
			if (sessionFactory == null) {
				reader = Resources.getResourceAsReader(resource);
				sessionFactory = new SqlSessionFactoryBuilder().build(reader);
			}
		} catch (IOException e) {
			//TODO
			e.printStackTrace();
		}
		return sessionFactory;
	}

}
